﻿@{
    Bundle("jquery_validate");
    Bundle("jquery_timepicker");
    Layout = "_Layout.cshtml";
}

@if(Model != null)
{
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('@ID("#form")').validate({
                rules: {
                    amount: {
                        required: true
                    },
                    usageNumber: {
                        required: true
                    }
                }
            });
            jQuery('@ID("#txt_valid_from")').datetimepicker();
            jQuery('@ID("#txt_valid_to")').datetimepicker();
        });
    </script>
    <form id="@ID("form")" action="@Url.Action(Loc.Act("Update").Ctrl("FixedDiscountRule"))" method="post">
        <input type="hidden" name="id" value="@JDM.Int32(Model.EntityID)" />
        <input type="hidden" name="commonFlags" value="None" />
        <input type="hidden" name="flags" value="None" />
        <table>
            <tr>
                <td>
                    <label>#</label>
                </td>
                <td>
                    <input type="text" readonly name="id" value="@JDM.Int32(Model.EntityID)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>&#10001;</label>
                </td>
                <td>
                    <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.CreatedOn))" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>&#10002;</label>
                </td>
                <td>
                    <input type="text" readonly value="@Svc.DateTime((DateTime)JDM.DateTime(Model.UpdatedOn))" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("ValidFrom"))</label>
                </td>
                <td>
                    <input id="@ID("txt_valid_from")" type="text" name="validFrom" value="@Svc.DateTime((DateTime)Model.ValidFrom)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("ValidTo"))</label>
                </td>
                <td>
                    <input id="@ID("txt_valid_to")" type="text" name="validTo" value="@Svc.DateTime((DateTime)Model.ValidTo)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Name"))</label>
                </td>
                <td>
                    <input type="text" name="name" value="@JDM.String(Model.Name)" maxlength="100" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("CouponCode"))</label>
                </td>
                <td>
                    <input type="text" name="couponCode" value="@JDM.String(Model.CouponCode)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("UsageNumber"))</label>
                </td>
                <td>
                    <input type="text" name="usageNumber" value="@JDM.Int32(Model.UsageNumber)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Amount"))</label>
                </td>
                <td>
                    <input type="text" name="amount" value="@Svc.Numeric((decimal)JDM.Decimal(Model.Amount))" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Scope"))</label>
                </td>
                <td>
                    <ul class="bar">
                        <li>
                            <input type="radio" name="commonFlags" value="ItemScope" @(JDM.String(Model.CommonFlags).Contains("ItemScope") ? "checked" : String.Empty) />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("ItemScope"))</label>
                        </li>
                        <li>
                            <input type="radio" name="commonFlags" value="OrderScope" @(JDM.String(Model.CommonFlags).Contains("OrderScope") ? "checked" : String.Empty) />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("OrderScope"))</label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Type"))</label>
                </td>
                <td>
                    <ul class="bar">
                        <li>
                            <input type="radio" name="flags" value="Value" @(JDM.HasFlags(Model.Flags, "Value") ? "checked" : String.Empty) />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("FixedDiscountRuleFlags").Name("Value"))</label>
                        </li>
                        <li>
                            <input type="radio" name="flags" value="Percent" @(JDM.HasFlags(Model.Flags, "Percent") ? "checked" : String.Empty) />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("FixedDiscountRuleFlags").Name("Percent"))</label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("Active"))</label>
                </td>
                <td>
                    <input type="checkbox" name="commonFlags" value="Active" @(JDM.String(Model.CommonFlags).Contains("Active") ? "checked" : String.Empty) />
                </td>
            </tr>
        </table>
        <ul class="bar toolbar">
            <li>
                <button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button>
            </li>
        </ul>
    </form>
}
else
{
    <script type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('@ID("#form")').validate({
                rules: {
                    amount: {
                        required: true
                    },
                    usageNumber: {
                        required: true
                    }
                }
            });
            jQuery('@ID("#txt_valid_from")').datetimepicker();
            jQuery('@ID("#txt_valid_to")').datetimepicker();
        });
    </script>
    <form id="@ID("form")" action="@Url.Action(Loc.Act("Create").Ctrl("FixedDiscountRule"))" method="post">
        <input type="hidden" name="commonFlags" value="None" />
        <input type="hidden" name="flags" value="None" />
        <table>
            <tr>
                <td>
                    <label>@T(Res.Name("ValidFrom"))</label>
                </td>
                <td>
                    <input id="@ID("txt_valid_from")" type="text" name="validFrom" value="@Svc.DateTime(DateTime.UtcNow)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("ValidTo"))</label>
                </td>
                <td>
                    <input id="@ID("txt_valid_to")" type="text" name="validTo" value="@Svc.DateTime(DateTime.UtcNow.AddMonths(1))" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Name"))</label>
                </td>
                <td>
                    <input type="text" name="name" maxlength="100" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("CouponCode"))</label>
                </td>
                <td>
                    <input type="text" name="couponCode" value="" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("UsageNumber"))</label>
                </td>
                <td>
                    <input type="text" name="usageNumber" value="-1" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Amount"))</label>
                </td>
                <td>
                    <input type="text" name="amount" value="@Svc.Numeric(Decimal.Zero)" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Scope"))</label>
                </td>
                <td>
                    <ul class="bar">
                        <li>
                            <input type="radio" name="commonFlags" value="ItemScope" />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("ItemScope"))</label>
                        </li>
                        <li>
                            <input type="radio" name="commonFlags" value="OrderScope" />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("OrderScope"))</label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.Name("Type"))</label>
                </td>
                <td>
                    <ul class="bar">
                        <li>
                            <input type="radio" name="flags" value="Value" />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("FixedDiscountRuleFlags").Name("Value"))</label>
                        </li>
                        <li>
                            <input type="radio" name="flags" value="Percent" />
                        </li>
                        <li>
                            <label>@T(Res.In("API").Of("Enum").Of("FixedDiscountRuleFlags").Name("Percent"))</label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>
                    <label>@T(Res.In("API").Of("Enum").Of("SalesRuleFlags").Name("Active"))</label>
                </td>
                <td>
                    <input type="checkbox" name="commonFlags" value="Active" />
                </td>
            </tr>
        </table>
        <ul class="bar toolbar">
            <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
        </ul>
    </form>
}